Home:ALL Converter>Mouseover event don't work (vanilla Javascript)

Mouseover event don't work (vanilla Javascript)

Ask Time:2021-04-12T02:31:49         Author:user15606194

Json Formatter

I want to make a battleship game and I have a problem with mouseover event in Javascript. I want to make a function that will change element's text content to "X" when is mouse over this element.

Javascript:

var gridShips = document.querySelectorAll('.ships');

for(var i=0; i++; i<gridShips.length){
    gridShips[i].addEventListener('mouseover', function(e){placeShips(e)}, false);
}
function placeShips(e){
e.target.textContent = 'X';

}

But when I get my mouse over this element nothing changes. Only when I click on this element, the text content is changing to 'X'. I don't know where is the problem.

Author:user15606194,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/67048776/mouseover-event-dont-work-vanilla-javascript
yy